	function getFormatDateYmd(n,v){			
		if(n=="") return n;
		n = String(n);
		
		return n.substr(0,4) +v+ n.substr(4,2) +v+ n.substr(6,2);
	}
	
	function getFormatDateMd(n,v){			
		if(n=="") return n;
		n = String(n);
		
		return n.substr(4,2) +v+ n.substr(6,2);
	}
	
	function getFormatTime(n,v){		
		if(n=="") return n;
		n = String(n);			
		return n.substr(0,2) +v+ n.substr(2,2);
	}
		
	function getFormatNumber(n){
		if(n=="") return n;
		n = String(n);			
		i = n.length;
		r = "";
		while(true){				
			if(i<=3) {
				r = n.substr(0,i) + r;					
				break;
			}
			r = ","+ n.substr(i-3,3) + r;				
			i-=3;
		}
		return r;
	}

	function clsSelfClubTop(){
			this._HTMLDom = null;
			this._init();
	}
	
	clsSelfClubTop.prototype = {
		_init: function(){
			var $layer = $("div#container>nav>ul.self_club_gnb");
			this._HTMLDom = {
				"$layer":$layer
			}
			this.bind();
		}
		, getBtnClubHome: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:first");
		}
		, getBtnClubField: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(1)");
		}
		, getBtnClubBoard: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(2)");
		}
		, getBtnClubPic: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(3)");
		}
		, getBtnClubAdmin: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(4)");
		}
		, bind: function(){
			//홈
			this.getBtnClubHome().click(function(event){
				event.preventDefault();						
				document.location.href = "home.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//자유게시판
			this.getBtnClubField().click(function(event){
				event.preventDefault();						
				document.location.href = "club_list.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//앨범게시판
			this.getBtnClubBoard().click(function(event){
				event.preventDefault();						
				document.location.href = "club_picture_list.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//동호회정기라운드
			this.getBtnClubPic().click(function(event){
				event.preventDefault();						
				document.location.href = "club_admin_rd.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//관리하기
			this.getBtnClubAdmin().click(function(event){
				event.preventDefault();						
				document.location.href = "club_admin_info.html?club_seq=" + (document.objUtil.getParam("club_seq"));				
			});
		}
	}
	
	
	function clsSelfClubAdminTop(){
		this._HTMLDom = null;
		this._init();
	}
	
	clsSelfClubAdminTop.prototype = {
		_init: function(){
			var $layer = $("div#container>section#main_content article.depth2_tab");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this._bind();
		}	
		, getBtnClubInfo: function(){
			return this._HTMLDom["$layer"].find("li:eq(0) a");	
		}
		, getBtnClubControl: function(){
			return this._HTMLDom["$layer"].find("li:eq(1) a");	
		}
		, getBtnClubOutMember: function(){
			return this._HTMLDom["$layer"].find("li:eq(2) a");	
		}
		, getBtnClubAssign: function(){
			return this._HTMLDom["$layer"].find("li:eq(3) a");	
		}
		, getBtnTag: function(){
			return this._HTMLDom["$layer"].find("li:eq(4) a");	
		}
		, getBtnClubClose: function(){
			return $("p.btn_depth a img[alt=동호회폐쇄]");
		}
		, _bind: function(){
			//동호회정보
			this.getBtnClubInfo().click(function(event){
				event.preventDefault();						
				alert()
				document.location.href = "club_admin_info.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//회원관리
			this.getBtnClubControl().click(function(event){
				event.preventDefault();						
				document.location.href = "club_admin_mem.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//탈퇴회원
			this.getBtnClubOutMember().click(function(event){
				event.preventDefault();						
				document.location.href = "club_admin_out.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//가입승인
			this.getBtnClubAssign().click(function(event){
				event.preventDefault();						
				document.location.href = "club_admin_join.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//쪽지보내기
			this.getBtnTag().click(function(event){
				event.preventDefault();						
				document.location.href = "club_admin_notelist.html?club_seq=" + (document.objUtil.getParam("club_seq"));
			});
			//동호회폐쇄
			this.getBtnClubClose().click(function(event){
				event.preventDefault();						
				var thisClass = document.objControl;
				if(!thisClass.objClubInfo.objRole.isAdmin()){
					alert(thisClass.objClubInfo.objRole.getError());
					return;	
				}
				
				var _url = "../popup/pop_club_close.html?club_seq=" + thisClass.club_seq;
				var winJoinClub = window.open(_url, "winJoinClub", "width=1024, height=570, scrollbars=no");
			});
		}
	}
	
	function clsRole(thisData){
		this.infoData = thisData;		
		this.errorMsg = null;		
		this._ERRMSG = {
			"_NOMEMBER": 	"동호회에 가입되지 않은 회원은 이용하실 수 없습니다."
			, "_NOADMIN": "동호회 매니저(개설자)만 이용하실 수 있습니다."
			, "_NOVIEW": "동호회 회원만 볼 수 있는 게시글입니다."
		}
	}	
	
	clsRole.prototype = {
		isMember: function(){	//0-가입회원,1~9=비회원,						
			if(this.infoData["가입여부"]=="0"){
				return true;	
			}else {
				this.errorMsg = this._ERRMSG["_NOMEMBER"];
				return false;
			}
			return false;
		}
		, isAdmin: function(){//0-일반회원,1-매니저/관리자
			if(this.infoData["내상태"]=="1"){
				return true;	
			}else {
				this.errorMsg = this._ERRMSG["_NOADMIN"];
				return false;
			}
			return false;
		}
		, isOpenView: function(viewType){
			if(viewType == "C"){//A-모두공개,C-회원공개
				if(!this.isMember()){
					this.errorMsg = this._ERRMSG["_NOVIEW"];
					return false;
				}
				return true;
			}
			return true;
		}
		, getError: function(){
			return this.errorMsg;	
		}	
	}
	
	// 동호회 정보
	function clsClubInfo()
	{
		this._HTMLDom = null;
		this.infoData = null;
		this._init();
		
	}
	
	clsClubInfo.prototype = {
		_init: function(){
			var $layer = $("div#container ul.self_c_name li:eq(0)");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$banner": $("div#container div.self_club_visual")
			}
		}
		, setData: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $banner = this._HTMLDom["$banner"];
			var thisClass = this;
						
			$layer.find("em").html(this.infoData["동호회명"]);
			
			$layer.find("span.open").contents().filter(function(){
				return (this.nodeType==3&&this.data.trim());
			}).after(this.infoData["클럽장"]["닉네임"]).remove();
			
			$layer.find("span.open").hover(function(){			
				_gf.showProfileLayer($(this), thisClass.infoData["클럽장"], "left", 25, 20);
			}, function(event){
				_gf.closeProfileLayer();
			});
				
			$layer.find("span:eq(0)").html(getFormatDateYmd(this.infoData["개설일"],".") + "(" + this.infoData["개설요일"] + ")");
			$layer.find("span.personnel").html(getFormatNumber(this.infoData["가입자수"]));
			$layer.find("span.comment").html(getFormatNumber(this.infoData["글수"]));
			
			if(this.infoData["가입여부"]=="0"){
				$layer.find("span:eq(4) a img").attr("src","../images/btn/btn_out03.gif").click(function(event){
					event.preventDefault();
					$(thisClass).trigger("clubClose");
				});
			}else if(this.infoData["가입여부"]=="1"){
				$layer.find("span:eq(4) a img").attr("src","../images/btn/btn_join.gif").click(function(event){
					event.preventDefault();
					alert("승인대기중입니다.");
				});
			}else {
				$layer.find("span:eq(4) a img").attr("src","../images/btn/btn_join.gif").click(function(event){
					event.preventDefault();
					$(thisClass).trigger("clubJoin");
				});
			}
			
			$banner.find("img").attr("src",this.infoData["스킨이미지"]).width("980").height("170");
		}
		// 가입하기 버튼
		, $getBtnJoin: function(){
			var $layer = this._HTMLDom["$layer"];			
			return $layer.find("span:eq(3) a");
		}
	}
	
	//나의동호회목록
	function clsClubMyList(){
		this._HTMLDom = null;
		this.clubMyList = null;
		
		this._init();
	}
	
	clsClubMyList.prototype = {
		_init: function(){
			var $layer = $("div#container ul.self_c_name li.right_note select#select");
			this._HTMLDom = {
				"$layer": $layer	
				, "$element": $layer.find("option:first")
			}
		}
		, setList: function(thisData){
			this.clubMyList = [{
				"동호회명": "나의 동호회 리스트"
				, "동호회키": ""
			}].concat(thisData);
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.empty();
			
			for(var i=0;i<this.clubMyList.length;++i){
				$layer.append($element.clone(true));	
			}
			
			$layer.find("option:first").attr("selected", "selected");
			
			$layer.find("option").each(function(n){			
				$(this).html(thisClass.clubMyList[n]["동호회명"]);
			});
			
			this._bind();
		}
		, _bind: function(){
			var $layer = this._HTMLDom["$layer"];
			var thisClass = this;
			
			$layer.change(function(event){
				var n = $layer.find("option").index($layer.find("option:selected"));				
				document.location.href = "home.html?club_my=&club_seq=" + thisClass.clubMyList[n]["동호회키"];	
			});
		}
	}
	
	function clsClubTopComm(){		
		this.clubInfo = null;
		this.clubInfoRequest = null;		
		this.clubMyList = null;
		this._init();
	}
	
	clsClubTopComm.prototype = {
		_init: function(){
			this.clubInfoRequest = {
				"동호회키": null
				, "동호회명": null
			}	
		}
		//------------------------ 동호회기본정보------------------------//		
		, getClubInfo: function(){
			var thisClass = this;
			var club_seq = this.clubInfoRequest["동호회키"];
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getClubInfo"
			}, {
				  "clubSeq": club_seq
			}, function(ret){
				
				// callback and mapping
				if(ret["msp"]["contents"]["items"]){					
					var obj = ret["msp"]["contents"]["items"];
					
					//동호회목록					
					thisClass.clubData = {
						"동호회명": _util.nvl(obj["clubName"])
						, "동호회키": _util.nvl(obj["clubSeq"])
						, "스킨이미지": _util.nvl(obj["skinUrl"])
						, "가입자수": _util.nvl(obj["memberCnt"])
						, "글수": _util.nvl(obj["totalBoardCnt"])
						, "개설일": _util.nvl(obj["regDate"])
						, "개설요일": _util.nvl(obj["regDay"])
						, "가입여부": _util.nvl(obj["clubMember"]["memberStatus"])
						, "가입질문": _util.nvl(obj["acceptQuestion"])
						, "가입유형": _util.nvl(obj["acceptYn"])
						, "내상태": _util.nvl(obj["clubMember"]["adminFlag"])
						, "동호회소개": _util.nvl(obj["clubDesc"])
						, "키워드":_util.nvl(obj["clubKeyword"])
						, "카테고리": {
							"카테고리키" : _util.nvl(obj["clubCategoryMaster"]["categoryId"])
							,"카테고리명" :_util.nvl(obj["clubCategoryMaster"]["categoryName"])
						}
						, "파일":{							
							 "상단파일": {
								 "파일키": _util.nvl(obj["skinFileSeq"])
								, "섬네일": "NOT"
								, "파일명": _util.nvl(obj["skinUrl"])
								, "원본파일명": "NOT"
							}
							, "배너파일": {
								"파일키": _util.nvl(obj["bannerFileSeq"])
								, "섬네일": "NOT"
								, "파일명": _util.nvl(obj["bannerUrl"])
								, "원본파일명": "NOT"
							}
							, "로고파일": {
								"파일키": _util.nvl(obj["logoFileSeq"])
								, "섬네일": "NOT"
								, "파일명": _util.nvl(obj["logoUrl"])
								, "원본파일명": "NOT"
							}
						}
						, "상단스킨": _util.nvl(obj["skinUrl"])
						, "배너이미지": _util.nvl(obj["bannerUrl"])
						, "로고이미지": _util.nvl(obj["logoUrl"])
						, "상단스킨구분": _util.nvl(obj["skinGb"])
						, "배너이미지구분": _util.nvl(obj["bannerGb"])
						, "로고이미지구분": _util.nvl(obj["logoGb"])
						, "클럽장": {
							"아이디": _util.nvl(obj["userMaster"]["userId"])
							, "닉네임":	_util.nvl(obj["userMaster"]["nickname"])
							, "이미지": _util.nvl(obj["userMaster"]["path"]) + _util.nvl(obj["userMaster"]["saveFileName"])
							, "성별": _util.nvl(obj["userMaster"]["sex"])
							, "핸디": _util.nvl(obj["userMaster"]["handi"])
							, "비거리": _util.nvl(obj["userMaster"]["region"])
						}
					};				
				}
				
				$(thisClass).trigger("evtFinishClubInfo");
			});			
			
		}
		, getClubInfoData: function(){
			return this.clubData;
		}
		, setClubInfoRequest: function(key,val){
			this.clubInfoRequest[key] = val;	
		}
		, getClubInfoRequest: function(key){
			return this.clubInfoRequest[key];	
		}
//------------------------ 동호회기본정보------------------------//		
//------------------------ 나의동호회리스트------------------------//		
		, getClubMyList: function(){			
			var thisClass = this;
			
			var szPage = 1;
			var szSortKey = 0;
			var szSortOption = 0;
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"getMyClubList",
				"listcount":99,
				"currpageno":szPage
			}, {
				  "sortBy": szSortKey
				  , "sortOption": szSortOption
			}, function(ret){
				
				// callback and mapping
				thisClass.clubMyList = [];
			
				if(ret["msp"]["contents"]["items"]){
					
					if(!ret["msp"]["contents"]["items"].length){
						ret["msp"]["contents"]["items"] = new Array(ret["msp"]["contents"]["items"]);
					}
					
					for(var i=0;i<ret["msp"]["contents"]["items"].length;i++){
						var obj = ret["msp"]["contents"]["items"][i];
						
						//동호회목록
						thisClass.clubMyList.push({
							"동호회키": _util.nvl(obj["clubSeq"])
							, "동호회명": _util.nvl(obj["clubName"])
							, "회원수": _util.nvl(obj["memberCnt"])
							, "게시글": _util.nvl(obj["newBoardCnt"])
							, "회원정보": {
								"회원구분명": _util.nvl(obj["clubMember"]["memberRoleName"])
								, "회원권한": _util.nvl(obj["clubMember"]["adminFlag"])
								, "가입일": _util.nvl(obj["clubMember"]["joinDate"])
							}
						});						
					}         
				}
				
				$(thisClass).trigger("evtFinishClubMyList");
			});			
		}
		, getClubMyListData: function(){
			return this.clubMyList;
		}
//------------------------ 나의동호회리스트------------------------//	
//------------------------ 동호회탈퇴------------------------//	
		, clubOutSubmit: function(arg){
			var thisClass = this;
			var szClubSeq = arg["동호회키"]
			
			// ajax 시작			
			//parameter setting and run
			_gf.ajax({
				"sid":"CL001",
				"servicename":"withdrawClub"
			}, {
				  "clubSeq": szClubSeq
				  , "userId": null
			}, function(ret){
				// callback and mapping
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"] == "00000"?true:false)
					, "메세지":  _gf.getResultMsg(ret,[""])
				}
				
				$(thisClass).trigger("evtFinishClubOut",[resData]);
			});
			// ajax 끝
		}
//------------------------ 동호회탈퇴------------------------//		
	}
	
	function clsClubTopControl(){
		this.club_seq = null;
		
		this.objClubTopComm = null;
		this.objClubInfo = null;
		this.objClubMyList = null;		
		this.objSelfClubTop = null;
		this.objSelfClubAdminTop = null;
		this.objRole = null;
	}
	
	clsClubTopControl.prototype = {
		_init: function(){
			this.club_seq = _util.getParam("club_seq");
			
			var member_id = _util.getCookie("member_id");
			
			if(!member_id) {
				/*
				if(confirm("로그인 후 이용하여 주세요.")){
					_gf.goLogin();						
				}else{
					document.location.href = "../club/club.html";
				}
				*/
			}
			
			if(!this.club_seq) {			
				document.location.href = "../club/club.html";
			}
			
			this.objClubTopComm = new clsClubTopComm();
			this.objClubInfo = new clsClubInfo();
			this.objClubMyList = new clsClubMyList();
			this.objSelfClubTop = new clsSelfClubTop();
			this.objSelfClubAdminTop = new clsSelfClubAdminTop();
			
			this._bind();
			
			//동호회정보
			this.objClubTopComm.setClubInfoRequest("동호회키",this.club_seq); 
			this.objClubTopComm.getClubInfo();
			//나의가입동호회			
			this.objClubTopComm.getClubMyList();
		}
		, _bind: function(){	
			var thisClass = this;
			
			// 동호회정보 조회 완료이벤트
			$(this.objClubTopComm).bind("evtFinishClubInfo", function(){
				var thisData = thisClass.objClubTopComm.getClubInfoData();				
				thisClass.objClubInfo.setData(thisData);				
			});
			
			// 나의동호회 리스트
			$(this.objClubTopComm).bind("evtFinishClubMyList", function(){
				var thisData = thisClass.objClubTopComm.getClubMyListData();
				thisClass.objClubMyList.setList(thisData);
			});	
			
			//탈퇴하기
			$(this.objClubInfo).bind("clubClose", function(event){
				event.preventDefault();		
				_gf.spinStart();		
				var submitData = {
					"동호회키" : thisClass.club_seq	
				}				
				thisClass.objClubTopComm.clubOutSubmit(submitData);
			});
						
			// 가입하기
			$(this.objClubInfo).bind("clubJoin", function(event){
				event.preventDefault();				
				if(thisClass.objClubInfo.infoData["가입유형"] == "Y"){
					document.location.href = "club_join1.html?club_seq="  + thisClass.club_seq;	
				}else if(thisClass.objClubInfo.infoData["가입유형"] == "N"){
					document.location.href = "club_join2.html?club_seq="  + thisClass.club_seq;	
				}
			});
			
			//동호회탈퇴 완료이벤트
			$(this.objClubTopComm).bind("evtFinishClubOut", function(event, resData){			
				_gf.spinEnd();	
				alert(resData["메세지"]);								
				if(resData["응답코드"]){
					document.location.href = "home.html?club_seq="  + thisClass.club_seq;
				}	
			});
		}
		, getClubSeq: function(){
			return this.club_seq;
		}
		, getClubInfo: function(){
			return this.objClubInfo;	
		}
		, getClubInfoData: function(){
			return this.objClubInfo.infoData;			
		}
		, getClubRole: function(){
			return this.objRole;	
		}
	}
	
document.objClubTopControl = new clsClubTopControl();
document.objClubTopControl._init();
_clubControl = document.objClubTopControl;
_clubInfo = document.objClubTopControl.getClubInfo();
_clubRole = document.objClubTopControl.getClubRole();